<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>

<script type="text/javascript">
    function openEdit(id) {
        var url = "/realty/edit";
        if (id != null && id != '')
            url += ("/" + id);
        window.location = url;
        return false;
    }
</script>
<sec:authorize access="hasAnyRole('EMPLOYEE','ADMIN')" var="authorized">
    <a href="#" onclick="openEdit();">Добавить</a>
</sec:authorize>
<table border="1">
    <tr>
        <th>Дата добавления</th>
        <th>Телефон</th>
        <th>ФИО</th>
        <th>Адрес</th>
        <th>Комнат</th>
        <th>Описание</th>
        <th>Комментарий</th>
    </tr>
    <c:forEach items="${realtyList}" var="realty">
        <tr class="listRow" <c:if test="${authorized}">onclick="openEdit('${realty.id}');"</c:if>>
            <td class="rowCell"><fmt:formatDate value="${realty.createDate.time}" pattern="dd.MM.yyyy HH:mm:ss"/></td>
            <td class="rowCell">${realty.phone}</td>
            <td class="rowCell">${realty.fio}</td>
            <td class="rowCell">${realty.address}</td>
            <td class="rowCell">${realty.rooms}</td>
            <td class="rowCell">${realty.description}</td>
            <td class="rowCell">${realty.comment}</td>
        </tr>
    </c:forEach>
</table>